package com.ruoyi.marketing.controller;

import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.marketing.service.MarketingAuth2Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @description: 
 *          ________
 *          ___  __/______________
 *          __  /_ ___  __ \  ___/
 *          _  __/ __  /_/ / /__
 *          /_/    _  .___/\___/
 *                 /_/
 * @author: www.fpcs.top
 *
 * @create: 2021-05-24 09:46
 */
@RestController
@RequestMapping("marketing/")
public class MarKetingAuth2Controller {
    public static final String CACHE_Auth2_KEY = "Auth2:";

    @Autowired
    private MarketingAuth2Service marketingAuth2Service;

    @GetMapping("callback")
    public void callback(String sate, String auth_code, HttpServletResponse response) throws IOException {
        boolean auth = marketingAuth2Service.auth(sate, auth_code);
        if (auth){
            response.sendRedirect("http://39.100.87.187/www/success.html");
        }else {
            response.sendRedirect("http://39.100.87.187/www/error.html");
        }
    }


    @GetMapping("refreshToken")
    public AjaxResult refreshToken(String key,String refreshToken){
        key = CACHE_Auth2_KEY + key;
       return marketingAuth2Service.refreshToken(key,refreshToken);
    }

    @GetMapping("aaa")
    public AjaxResult aaa(String refreshToken){
        return marketingAuth2Service.aaa(refreshToken);
    }
}